﻿package mortal.game.view.platform
{
    import Message.DB.Tables.*;
    import __AS3__.vec.*;
    import com.gengine.global.*;
    import com.gengine.resource.*;
    import flash.utils.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.view.common.*;
    import mortal.game.view.platform.platformTencent.*;

    public class PlatformGiftConfig extends Object
    {
        public var giftDic:Dictionary;
        private var _enterType:int;
        private var _platGiftDic:Dictionary;
        private var _vipGiftVec:Vector.<TPlatformGift>;
        private var _xufeiGift:TPlatformGift;
        private var _newHandGift:TPlatformGift;
        private var _dailyLoginGift:TPlatformGift;
        private var _dailyDeluxeGift:TPlatformGift;
        private var _levelGiftVec:Vector.<TPlatformGift>;
        private static var _instance:PlatformGiftConfig;

        public function PlatformGiftConfig()
        {
            this._enterType = ParamsConst.instance.enterType;
            if (_instance != null)
            {
                throw new Error(" platformGiftConfig 单例 ");
            }
            this.init();
            return;
        }// end function

        public function init() : void
        {
            var _loc_1:* = ConfigManager.instance.getJSONByFileName("t_platform_gift.json");
            this.write(_loc_1);
            return;
        }// end function

        private function write(param1:Object) : void
        {
            var _loc_2:TPlatformGift = null;
            var _loc_3:Object = null;
            for each (_loc_3 in param1)
            {
                
                if (!this.giftDic)
                {
                    this.giftDic = new Dictionary();
                }
                _loc_2 = new TPlatformGift();
                _loc_2.proxy = "0";
                _loc_2.proxyEx = 0;
                ClassTypesUtil.copyValue(_loc_2, _loc_3);
                if (!this.giftDic[_loc_2.proxy])
                {
                    this.giftDic[_loc_2.proxy] = new Dictionary();
                }
                if (_loc_2.proxyEx == 0)
                {
                    this.giftDic[_loc_2.proxy][_loc_2.id] = _loc_2;
                    continue;
                }
                if (_loc_2.proxyEx == ParamsConst.instance.enterType)
                {
                    this.giftDic[_loc_2.proxy][_loc_2.id] = _loc_2;
                }
            }
            return;
        }// end function

        private function get platGiftDic() : Dictionary
        {
            if (!this._platGiftDic)
            {
                if (Global.isDebugModle)
                {
                    this._platGiftDic = this.giftDic[ParamsConst.instance.platformProxy.toString()];
                }
                else
                {
                    this._platGiftDic = this.giftDic[Cache.instance.role.entityInfo.entityId.typeEx2.toString()];
                }
            }
            return this._platGiftDic;
        }// end function

        public function getGiftNoPlan(param1:int) : TPlatformGift
        {
            var _loc_3:TPlatformGift = null;
            var _loc_4:Object = null;
            var _loc_2:* = this.giftDic["0"];
            for each (_loc_4 in _loc_2)
            {
                
                _loc_3 = _loc_4 as TPlatformGift;
                if (param1 == _loc_3.extend)
                {
                    return _loc_3;
                }
            }
            return null;
        }// end function

        public function getGift(param1:int, param2:int = 0) : TPlatformGift
        {
            var _loc_5:Object = null;
            var _loc_3:* = new TPlatformGift();
            var _loc_4:* = this.platGiftDic;
            if (!_loc_4)
            {
                if (param1 == PlatformGiftConst.DownLoadGift)
                {
                    _loc_4 = this.giftDic["8"];
                }
            }
            if (_loc_4)
            {
                for each (_loc_5 in _loc_4)
                {
                    
                    _loc_3 = _loc_5 as TPlatformGift;
                    if (param2 > 0)
                    {
                        if (param2 == _loc_3.pLv)
                        {
                            return _loc_3;
                        }
                        continue;
                    }
                    if (param1 == _loc_3.extend)
                    {
                        return _loc_3;
                    }
                }
            }
            return _loc_3;
        }// end function

        public function getPlatformGiftById(param1:int) : TPlatformGift
        {
            var _loc_2:TPlatformGift = null;
            for each (_loc_2 in this.platGiftDic)
            {
                
                if (_loc_2.id == param1)
                {
                    return _loc_2;
                }
            }
            return null;
        }// end function

        public function get vipGiftVec() : Vector.<TPlatformGift>
        {
            var vec:Vector.<TPlatformGift>;
            var info:TPlatformGift;
            var platformGiftDic:Dictionary;
            var sortFunc:Function;
            var o:Object;
            if (!this._vipGiftVec)
            {
                vec = new Vector.<TPlatformGift>;
                platformGiftDic = this.platGiftDic;
                sortFunc = function (param1:TPlatformGift, param2:TPlatformGift) : Number
            {
                if (param1 == null || param1 == null)
                {
                    return 1;
                }
                if (param1.id > param2.id)
                {
                    return 1;
                }
                if (param1.id < param2.id)
                {
                    return -1;
                }
                return 0;
            }// end function
            ;
                if (platformGiftDic)
                {
                    var _loc_2:int = 0;
                    var _loc_3:* = platformGiftDic;
                    while (_loc_3 in _loc_2)
                    {
                        
                        o = _loc_3[_loc_2];
                        info = o as TPlatformGift;
                        if (info.pLv > 0)
                        {
                            vec.push(info);
                        }
                    }
                    vec.sort(sortFunc);
                    var _loc_2:int = 0;
                    var _loc_3:* = platformGiftDic;
                    while (_loc_3 in _loc_2)
                    {
                        
                        o = _loc_3[_loc_2];
                        info = o as TPlatformGift;
                        if (info.extend == 1)
                        {
                            vec.push(info);
                        }
                    }
                }
                this._vipGiftVec = vec;
            }
            return this._vipGiftVec;
        }// end function

        public function get xufeiGift() : TPlatformGift
        {
            var _loc_1:Dictionary = null;
            var _loc_2:Object = null;
            var _loc_3:TPlatformGift = null;
            if (!this._xufeiGift)
            {
                _loc_1 = this.platGiftDic;
                for each (_loc_2 in _loc_1)
                {
                    
                    _loc_3 = _loc_2 as TPlatformGift;
                    if (_loc_3.extend == PlatformGiftConst.QQXufeiGift)
                    {
                        this._xufeiGift = _loc_3;
                        break;
                    }
                }
            }
            return this._xufeiGift;
        }// end function

        public function get newHandGift() : TPlatformGift
        {
            var _loc_1:Dictionary = null;
            var _loc_2:Object = null;
            var _loc_3:TPlatformGift = null;
            if (!this._newHandGift)
            {
                _loc_1 = this.platGiftDic;
                for each (_loc_2 in _loc_1)
                {
                    
                    _loc_3 = _loc_2 as TPlatformGift;
                    if (_loc_3.extend == PlatformGiftConst.QQNewHandGift)
                    {
                        this._newHandGift = _loc_3;
                        break;
                    }
                }
            }
            return this._newHandGift;
        }// end function

        public function get dailyLoginGift() : TPlatformGift
        {
            var _loc_1:Dictionary = null;
            var _loc_2:Object = null;
            var _loc_3:TPlatformGift = null;
            if (!this._dailyLoginGift)
            {
                _loc_1 = this.platGiftDic;
                for each (_loc_2 in _loc_1)
                {
                    
                    _loc_3 = _loc_2 as TPlatformGift;
                    if (_loc_3.extend == PlatformGiftConst.QQYearGift)
                    {
                        this._dailyLoginGift = _loc_3;
                        break;
                    }
                }
            }
            return this._dailyLoginGift;
        }// end function

        public function get dailyDeluxeGift() : TPlatformGift
        {
            var _loc_1:Dictionary = null;
            var _loc_2:Object = null;
            var _loc_3:TPlatformGift = null;
            if (!this._dailyDeluxeGift)
            {
                _loc_1 = this.platGiftDic;
                for each (_loc_2 in _loc_1)
                {
                    
                    _loc_3 = _loc_2 as TPlatformGift;
                    if (_loc_3.extend == PlatformGiftConst.QQDeluxeGift)
                    {
                        this._dailyDeluxeGift = _loc_3;
                        break;
                    }
                }
            }
            return this._dailyDeluxeGift;
        }// end function

        public function get levelGiftVec() : Vector.<TPlatformGift>
        {
            var platformGiftDic:Dictionary;
            var o:Object;
            var sortFunc:Function;
            var info:TPlatformGift;
            if (!this._levelGiftVec)
            {
                this._levelGiftVec = new Vector.<TPlatformGift>;
                platformGiftDic = this.platGiftDic;
                var _loc_2:int = 0;
                var _loc_3:* = platformGiftDic;
                while (_loc_3 in _loc_2)
                {
                    
                    o = _loc_3[_loc_2];
                    info = o as TPlatformGift;
                    if (info.extend == PlatformGiftConst.LevelGift)
                    {
                        this._levelGiftVec.push(info);
                    }
                }
                sortFunc = function (param1:TPlatformGift, param2:TPlatformGift) : Number
            {
                if (param1 == null || param1 == null)
                {
                    return 1;
                }
                if (param1.lvLimit > param2.lvLimit)
                {
                    return 1;
                }
                if (param1.lvLimit < param2.lvLimit)
                {
                    return -1;
                }
                return 0;
            }// end function
            ;
                this._levelGiftVec.sort(sortFunc);
            }
            return this._levelGiftVec;
        }// end function

        public static function get instance() : PlatformGiftConfig
        {
            if (_instance == null)
            {
                _instance = new PlatformGiftConfig;
            }
            return _instance;
        }// end function

    }
}
